#include <vector>
#include <string>

using namespace std;

void errprintline (const char *msg, int line);

class Memory
{
	private:
		class CacheStack
		{
		public:
#			define WRITE	1024
#			define VALID 	512
#			define TAG	256
#			define INDEX	255
				
			int nhit, nmiss, setNum;
			int mainMem[256];
			int frame [16], tags [16];
			
			CacheStack ();	
			CacheStack (int setNum);
			int& operator[] (int index);
/*			const int operator[] (int index);*/
		};
	public:
		// Instruction Vector
		vector<string> Text;
		// Memory
		int selectMemLoc, immedValue;
		CacheStack Stack;
		int *nhit, *nmiss;

		Memory ();
		Memory (int setNum);
		~Memory ();

		// Gets the number of instructions
		int getInstructionCount ();
		// Pushes an instruction at the end of the iv
		int pushInstruction (string inst);
		// Insert an instruction at the specified index
		int insertInstruction (int index, string inst);
		// Get an instruction at the specified index
		string getInstruction (int index);
		// Modify an instruction at the specified index
		int modifyInstruction (int index, string inst);

		// Selects memory location
		void SelectMemLocation (int memloc);
		// Read from memory
		int ReadFromStack (int index);
		// Read from selected memory location
		int ReadFromSelectedLoc ();
		// Write to memory
		int WriteToStack (int index, int value);
		// Write to selected loc
		int WriteToSelectedLoc (int value);
		// Write to immed value
		void WriteImmedValue (int value);
		// Read from immed value
		int ReadImmedValue ();
		void errprint (const char *msg);
};
